<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:system="clr-namespace:System;assembly=mscorlib"
  xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
  xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf"
  xmlns:guiHelper="clr-namespace:DentalGUIHelper;assembly=DentalConfig">

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="../Brushes/MaterialDesign/MaterialDesignTheme.Theme.xaml"/>
    <ResourceDictionary Source="MaterialDesignTheme.ValidationErrorTemplate.xaml"/>
  </ResourceDictionary.MergedDictionaries>

  <converters:BooleanToVisibilityConverter x:Key="InverseBoolToVisConverter" TrueValue="Collapsed" FalseValue="Visible"/>
  <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

  <Style x:Key="MaterialDesignPasswordBox" TargetType="{x:Type PasswordBox}">
    <Style.Resources>
      <Style TargetType="{x:Type TextBlock}" BasedOn="{x:Null}"/>
    </Style.Resources>
    <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
    <Setter Property="FontFamily" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.FontFamily)}"/>
    <Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignTextBoxBorder}"/>
    <Setter Property="PasswordChar" Value="•"/>
    <Setter Property="BorderThickness" Value="0 0 0 1"/>
    <Setter Property="wpf:TextFieldAssist.TextBoxViewMargin" Value="1 0 0 0"/>
    <Setter Property="wpf:HintAssist.Hint" Value="Password"/>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="CaretBrush" Value="{Binding RelativeSource={RelativeSource Self}, Path=Foreground}"/>
    <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="VerticalContentAlignment" Value="Bottom"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="AllowDrop" Value="true"/>
    <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
    <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    <Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorTemplate}"/>
    <Setter Property="wpf:ValidationAssist.Suppress" Value="True"/>
    <Setter Property="ContextMenu">
      <Setter.Value>
        <ContextMenu>
          <MenuItem Command="Cut">
            <MenuItem.Icon>
              <wpf:PackIcon Kind="ContentCut"/>
            </MenuItem.Icon>
          </MenuItem>
          <MenuItem Command="Copy">
            <MenuItem.Icon>
              <wpf:PackIcon Kind="ContentCopy"/>
            </MenuItem.Icon>
          </MenuItem>
          <MenuItem Command="Paste">
            <MenuItem.Icon>
              <wpf:PackIcon Kind="ContentPaste"/>
            </MenuItem.Icon>
          </MenuItem>
        </ContextMenu>
      </Setter.Value>
    </Setter>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type PasswordBox}">
          <Grid>
            <VisualStateManager.VisualStateGroups>
              <VisualStateGroup x:Name="FocusStates">
                <VisualState x:Name="Focused">
                  <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="ScaleTransform" From="0" To="1" Duration="0:0:0.3">
                      <DoubleAnimation.EasingFunction>
                        <SineEase EasingMode="EaseOut"/>
                      </DoubleAnimation.EasingFunction>
                    </DoubleAnimation>
                    <DoubleAnimation Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="ScaleTransform" From="0" To="1" Duration="0:0:0.3">
                      <DoubleAnimation.EasingFunction>
                        <SineEase EasingMode="EaseOut"/>
                      </DoubleAnimation.EasingFunction>
                    </DoubleAnimation>
                    <DoubleAnimation Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="ScaleTransform" To="0" BeginTime="0:0:0.45" Duration="0"/>
                    <DoubleAnimation Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="ScaleTransform" To="0" BeginTime="0:0:0.45" Duration="0"/>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Unfocused">
                  <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="ScaleTransform" To="0" Duration="0"/>
                    <DoubleAnimation Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="ScaleTransform" To="0" Duration="0"/>
                  </Storyboard>
                </VisualState>
              </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Border
              HorizontalAlignment="Stretch"
              VerticalAlignment="Stretch"
              Background="{TemplateBinding Foreground}"
              Opacity="0.08"
              CornerRadius="{Binding Path=(wpf:TextFieldAssist.TextFieldCornerRadius), RelativeSource={RelativeSource TemplatedParent}}"
              Visibility="{Binding Path=(wpf:TextFieldAssist.RippleOnFocusEnabled), RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"
              RenderTransformOrigin="0.5,0.5">
              <Border.RenderTransform>
                <ScaleTransform x:Name="ScaleTransform" ScaleX="0" ScaleY="0" />
              </Border.RenderTransform>
            </Border>
            <Border x:Name="passwordFieldBoxBorder" CornerRadius="{Binding Path=(wpf:TextFieldAssist.TextFieldCornerRadius), RelativeSource={RelativeSource TemplatedParent}}" SnapsToDevicePixels="True">
              <Grid>
                <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True" Padding="0 4 0 2">
                  <Grid x:Name="passwordFieldGrid" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
                    <ScrollViewer
                      x:Name="PART_ContentHost"
                      Focusable="false"
                      HorizontalScrollBarVisibility="Hidden"
                      VerticalScrollBarVisibility="Hidden"
                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                      UseLayoutRounding="{TemplateBinding UseLayoutRounding}"/>
                    <wpf:SmartHint
                      x:Name="Hint"
                      HintProxy="{Binding RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static converters:HintProxyFabricConverter.Instance}}"
                      HintOpacity="{Binding Path=(wpf:HintAssist.HintOpacity), RelativeSource={RelativeSource TemplatedParent}}"
                      UseFloating="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource TemplatedParent}}"
                      FloatingScale="{Binding Path=(wpf:HintAssist.FloatingScale), RelativeSource={RelativeSource TemplatedParent}}"
                      FloatingOffset="{Binding Path=(wpf:HintAssist.FloatingOffset), RelativeSource={RelativeSource TemplatedParent}}"
                      FontSize="{TemplateBinding FontSize}"
                      FontFamily="{TemplateBinding FontFamily}"
                      Padding="{TemplateBinding Padding}">
                      <wpf:SmartHint.Resources>
                        <system:Double x:Key="DisabledOpacity">1</system:Double><!--TextBlock disabled opacity should not be applied on top of HintOpacity-->
                      </wpf:SmartHint.Resources>
                      <wpf:SmartHint.Hint>
                        <StackPanel Orientation="Horizontal">
                          <ContentPresenter Content="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Center"/>
                          <TextBlock Text="*" Margin="4,0,0,0" VerticalAlignment="Center" Visibility="{Binding Path=(guiHelper:TextboxHelper.IsRequired), RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                        </StackPanel>
                      </wpf:SmartHint.Hint>
                    </wpf:SmartHint>
                  </Grid>
                </Border>
                <Border
                  x:Name="passwordFieldBoxBottomLine"
                  Background="{TemplateBinding BorderBrush}"
                  Height="0"
                  CornerRadius="{Binding Path=(wpf:TextFieldAssist.UnderlineCornerRadius), RelativeSource={RelativeSource TemplatedParent}}"
                  HorizontalAlignment="Stretch"
                  VerticalAlignment="Bottom"
                  SnapsToDevicePixels="True"/>
                <Line
                  x:Name="DashedLine"
                  VerticalAlignment="Bottom"
                  Visibility="Hidden"
                  StrokeThickness="1.25"
                  StrokeDashArray="1,2.5"
                  StrokeDashCap="Round"
                  X1="0"
                  X2="{Binding ActualWidth, ElementName=border}"
                  Y1="0"
                  Y2="0"
                  Stroke="{TemplateBinding BorderBrush}"
                  Opacity="{StaticResource DisabledOpacity}"/>
                <wpf:Underline
                  x:Name="Underline"
                  Visibility="{Binding Path=(wpf:TextFieldAssist.DecorationVisibility), RelativeSource={RelativeSource TemplatedParent}}"
                  CornerRadius="{Binding Path=(wpf:TextFieldAssist.UnderlineCornerRadius), RelativeSource={RelativeSource TemplatedParent}}"/>
              </Grid>
            </Border>
          </Grid>
          <ControlTemplate.Triggers>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="wpf:HintAssist.IsFloating" Value="True"/>
                <Condition Property="IsKeyboardFocused" Value="True"/>
              </MultiTrigger.Conditions>
              <Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource MidContrastPrimaryBrush}"/>
              <Setter TargetName="Hint" Property="HintOpacity" Value="1"/>
            </MultiTrigger>
            <Trigger Property="wpf:HintAssist.IsFloating" Value="True">
              <Setter TargetName="border" Property="Padding" Value="0 15.5 0 4"/>
            </Trigger>
            <MultiDataTrigger>
              <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource Self}}" Value="False" />
                <Condition Binding="{Binding Path=(guiHelper:TextboxHelper.HintIsVisible), RelativeSource={RelativeSource Self}}" Value="False"/>
              </MultiDataTrigger.Conditions>
              <Setter TargetName="Hint" Property="Visibility" Value="Collapsed" />
            </MultiDataTrigger>
            <Trigger Property="wpf:TextFieldAssist.HasFilledTextField" Value="True">
              <Setter Property="VerticalContentAlignment" Value="Top"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="Background" Value="{DynamicResource MaterialDesignTextFieldBoxBackground}"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="Padding" Value="0,8,0,0"/>
              <Setter TargetName="passwordFieldGrid" Property="Margin" Value="16,0,16,0"/>
              <Setter TargetName="border" Property="BorderThickness" Value="0"/>
              <Setter TargetName="border" Property="Cursor" Value="IBeam"/>
              <Setter TargetName="Hint" Property="Margin" Value="0,0,0,16"/>
              <Setter TargetName="PART_ContentHost" Property="Margin" Value="0,8,0,8"/>
            </Trigger>
            <Trigger Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="True">
              <Setter Property="VerticalContentAlignment" Value="Top"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="Background" Value="Transparent"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="BorderThickness" Value="1"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="BorderBrush" Value="{DynamicResource MaterialDesignTextAreaBorder}"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="Padding" Value="0,8,0,0"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="Margin" Value="-1"/>
              <Setter TargetName="passwordFieldGrid" Property="Margin" Value="16,0,16,0"/>
              <Setter TargetName="border" Property="BorderThickness" Value="0"/>
              <Setter TargetName="border" Property="Cursor" Value="IBeam"/>
              <Setter TargetName="Underline" Property="Visibility" Value="Collapsed"/>
              <Setter TargetName="Hint" Property="Margin" Value="0,0,0,16"/>
              <Setter TargetName="PART_ContentHost" Property="Margin" Value="0,8,0,8"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Opacity" TargetName="border" Value="{StaticResource DisabledOpacity}"/>
              <Setter TargetName="border" Property="BorderBrush" Value="Transparent"/>
              <Setter TargetName="Hint" Property="HintOpacity" Value="1"/>
            </Trigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsEnabled" Value="false"/>
                <Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="True"/>
              </MultiTrigger.Conditions>
              <Setter TargetName="passwordFieldBoxBorder" Property="BorderBrush" Value="{DynamicResource MaterialDesignTextAreaInactiveBorder}"/>
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsEnabled" Value="false"/>
                <Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="False"/>
              </MultiTrigger.Conditions>
              <Setter Property="Opacity" TargetName="border" Value="{StaticResource DisabledOpacity}"/>
              <Setter TargetName="border" Property="BorderBrush" Value="Transparent"/>
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsEnabled" Value="false"/>
                <Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="False"/>
                <Condition Property="wpf:TextFieldAssist.HasFilledTextField" Value="False"/>
              </MultiTrigger.Conditions>
              <Setter TargetName="DashedLine" Property="Visibility" Value="Visible"/>
            </MultiTrigger>
            <Trigger Property="IsKeyboardFocused" Value="true">
              <Setter TargetName="Underline" Property="IsActive" Value="True"/>
            </Trigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsKeyboardFocused" Value="True"/>
                <Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="True"/>
              </MultiTrigger.Conditions>
              <Setter TargetName="passwordFieldBoxBorder" Property="Margin" Value="-2"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="BorderThickness" Value="2"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="BorderBrush" Value="{DynamicResource MidContrastPrimaryBrush}"/>
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsKeyboardFocused" Value="True"/>
                <Condition Property="wpf:TextFieldAssist.HasFilledTextField" Value="True"/>
              </MultiTrigger.Conditions>
              <Setter TargetName="passwordFieldBoxBottomLine" Property="Height" Value="2"/>
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsMouseOver" Value="True"/>
                <Condition Property="wpf:TextFieldAssist.HasFilledTextField" Value="False"/>
                <Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="False"/>
                <Condition Property="wpf:TextFieldAssist.NewSpecHighlightingEnabled" Value="False"/>
              </MultiTrigger.Conditions>
              <Setter Property="BorderBrush" Value="{DynamicResource MidContrastPrimaryBrush}"/>
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsMouseOver" Value="True"/>
                <Condition Property="wpf:TextFieldAssist.HasFilledTextField" Value="False"/>
                <Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="False"/>
                <Condition Property="wpf:TextFieldAssist.NewSpecHighlightingEnabled" Value="True"/>
              </MultiTrigger.Conditions>
              <Setter TargetName="border" Property="BorderThickness" Value="0,0,0,2"/>
              <Setter TargetName="border" Property="Padding" Value="0,4,0,3"/>
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsMouseOver" Value="True"/>
                <Condition Property="wpf:TextFieldAssist.HasFilledTextField" Value="True"/>
              </MultiTrigger.Conditions>
              <Setter TargetName="passwordFieldBoxBorder" Property="Background" Value="{Binding Background, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
              <Setter TargetName="passwordFieldBoxBottomLine" Property="Height" Value="1"/>
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsMouseOver" Value="True"/>
                <Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="True"/>
              </MultiTrigger.Conditions>
              <Setter TargetName="passwordFieldBoxBorder" Property="Margin" Value="-2"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="BorderThickness" Value="2"/>
            </MultiTrigger>
            <Trigger Property="Validation.HasError" Value="true">
              <Setter Property="BorderBrush" Value="{DynamicResource ValidationErrorBrush}"/>
              <Setter TargetName="Underline" Property="Background" Value="{DynamicResource ValidationErrorBrush}"/>
            </Trigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="Validation.HasError" Value="True"/>
                <Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="True"/>
              </MultiTrigger.Conditions>
              <Setter TargetName="passwordFieldBoxBorder" Property="Margin" Value="-2"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="BorderThickness" Value="2"/>
              <Setter TargetName="passwordFieldBoxBorder" Property="BorderBrush" Value="{DynamicResource ValidationErrorBrush}"/>
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="Validation.HasError" Value="True"/>
                <Condition Property="wpf:ValidationAssist.Suppress" Value="True"/>
              </MultiTrigger.Conditions>
              <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)/ErrorContent}"/>
            </MultiTrigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Style.Triggers>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
          <Condition Property="IsSelectionActive" Value="false"/>
        </MultiTrigger.Conditions>
        <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
      </MultiTrigger>
      <Trigger Property="guiHelper:TextboxHelper.IsRequired" Value="True">
        <Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorNoAsteriskTemplate}" />
      </Trigger>
    </Style.Triggers>
  </Style>

  <Style x:Key="MaterialDesignFloatingHintPasswordBox" TargetType="{x:Type PasswordBox}" BasedOn="{StaticResource MaterialDesignPasswordBox}">
    <Setter Property="wpf:HintAssist.IsFloating" Value="True"/>
  </Style>

  <Style x:Key="MaterialDesignFilledPasswordFieldPasswordBox" TargetType="{x:Type PasswordBox}" BasedOn="{StaticResource MaterialDesignFloatingHintPasswordBox}">
    <Setter Property="wpf:TextFieldAssist.HasFilledTextField" Value="True"/>
    <Setter Property="wpf:TextFieldAssist.RippleOnFocusEnabled" Value="True"/>
    <Setter Property="wpf:TextFieldAssist.TextFieldCornerRadius" Value="4,4,0,0"/>
    <Setter Property="wpf:TextFieldAssist.UnderlineCornerRadius" Value="0"/>
  </Style>

  <Style x:Key="MaterialDesignOutlinedPasswordFieldPasswordBox" TargetType="{x:Type PasswordBox}" BasedOn="{StaticResource MaterialDesignFloatingHintPasswordBox}">
    <Setter Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="True"/>
    <Setter Property="wpf:TextFieldAssist.TextFieldCornerRadius" Value="4"/>
  </Style>

  <Style x:Key="{x:Type PasswordBox}" BasedOn="{StaticResource MaterialDesignPasswordBox}" TargetType="{x:Type PasswordBox}"/>

</ResourceDictionary>
